package com.dc.designPattern._8_composite.impl;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * Description: 组合模式，组件_大学
 *
 *  Composite :非叶子节点，用于存储子部件，在 Component 接口中实现 子部件的相关操作，比如增加(add), 删除。
 *
 * @author: gdc
 * @date: 2021/3/14
 * @version 1.0
 */
public class University extends OrganizationComponent {

    private List<OrganizationComponent> organizationComponents = Lists.newArrayList();

    public University(String name, String desc) {
        super(name, desc);
    }

    /**
     * 重写add方法
     * @param organizationComponent            组织组件信息
     */
    @Override
    protected void add(OrganizationComponent organizationComponent) {
        organizationComponents.add(organizationComponent);
    }

    /**
     * 重写remove方法
     * @param organizationComponent            组织组件信息
     */
    @Override
    protected void remove(OrganizationComponent organizationComponent) {
        organizationComponents.remove(organizationComponent);
    }

    @Override
    protected void print() {
        System.out.println(" ===============" + getName() + "============= ");
        organizationComponents.forEach(OrganizationComponent::print);
    }
}
